#!/usr/bin/env python
#coding=utf-8
from django.contrib import admin
from ishare.core.models import Property
from ishare.core.models import ShareItem
from ishare.core.models import Interesting
from ishare.core.models import Category
from ishare.core.models import City
from ishare.core.models import Label
from ishare.core.models import ItemImage
from ishare.core.models import UserProfile
from ishare.core.models import Event
from django.contrib.contenttypes.generic import GenericInlineModelAdmin

class PropertyInline(admin.TabularInline):
    model = Property

class InterestingInline(admin.TabularInline):
    model = Interesting

class ItemImageInline(admin.TabularInline):
    model = ItemImage

class LabelInline(GenericInlineModelAdmin):
    model = Label

class ShareItemAdmin(admin.ModelAdmin):
    list_display = ['name','category','description','owner','status','view_count','picture']
    list_filter = ['status','add_time','category']
    ordering = ['add_time']
    search_fields = ['name','description']
    save_on_top = False
    list_per_page = 20
    
    inlines = [PropertyInline,ItemImageInline,InterestingInline]

admin.site.register(ShareItem, ShareItemAdmin)

class CategoryAdmin(admin.ModelAdmin):
    list_display = ['name','parent']
    ordering = ['parent']
    search_fields = ['name']

admin.site.register(Category, CategoryAdmin)

class CityAdmin(admin.ModelAdmin):
    list_display = ['name']
    search_fields = ['name']

admin.site.register(City, CityAdmin)

class UserProfileAdmin(admin.ModelAdmin):
    list_display = ['user','gender','city','face_img','site']
    search_fields = ['user','city','site']
    list_filter = ['gender','city']

admin.site.register(UserProfile, UserProfileAdmin)

class EventAdmin(admin.ModelAdmin):
    list_display = ['who','when','content_type','object_id','event_type']
    list_filter = ['when','event_type']
    ordering = ['-when']

admin.site.register(Event, EventAdmin)
